#!/bin/bash


#目标对象, 拼成一个 sql 语句来 把 CSV 数据装入 mysql
FINAL_SQL=""



#
# @param1  file_path
# @param2  table_name
# @param3  columns  eg   'usernmae,password,@age'
# @param4  extend_part  额外设置部分 (如果你有某列需要改动或者想要新增某列, 这个字段不可少, 并且 @param3  columns 也要做出相应改变)
# eg :  age=@age ,  sync_date='2024-07-05'
# 构造器
function  BUILD_COMMAND_SQL(){


   # echo $1
   # echo $2
   # echo $3

   local   file_path=$1
   local   table_name=$2
   local   columns=$3
   local   extend_part=$4

   local load_instruction="LOAD DATA local INFILE   $file_path  "
   local into_table_instruction="  INTO TABLE   $table_name  "
   local separator_instruction=" CHARACTER SET utf8  FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'  IGNORE 1 LINES "
   local columns_instruction="("$columns")"

   # FINAL_SQL=$load_instruction   $into_table_instruction $separator_instruction  $columns_instruction  # INTO: command not found  有空格
   FINAL_SQL=''
   if [[ $extend_part == '' ]]; then
      FINAL_SQL="$load_instruction   $into_table_instruction $separator_instruction  $columns_instruction"
   else
      FINAL_SQL="$load_instruction   $into_table_instruction $separator_instruction  $columns_instruction  set  $extend_part "
   fi


   return 1
}